#import "OmDestinyListVC.h"
#import "OmDestinyListVCTableViewCell.h"
#import "OmUserPageVC.h"
#define CellReuseID @"OmDestinyListVCTableViewCell"
@interface OmDestinyListVC () <UITableViewDelegate, UITableViewDataSource, UIScrollViewRefreshDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation OmDestinyListVC
#pragma mark - Event
- (void)refreshSelf {
    [self.tableView.mj_header beginRefreshing];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableView.refreshDataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OmDestinyListVCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellReuseID];
    UserApiGetUserLikeLogModel *model = tableView.refreshDataArray[indexPath.row];
    cell.model = model;
    if (self.listType != OmDestinyListVCTypeILike) {
        [cell hideSendGiftButton];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    OmUserPageVC *vc = [[OmUserPageVC alloc] init];
    UserApiGetUserLikeLogModel *model = tableView.refreshDataArray[indexPath.row];
    vc.ID = model.my_like_uid;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)scrollView:(UIScrollView *)scrollView didBeginRefresh:(UIScrollView *(^)(NSMutableArray *))refreshData {
    NSString *url = [[CYURLUtils sharedCYURLUtils] makeURLWithC:@"user_api" A:@"get_user_like_log"];
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"uid"] = curUser.id;
    param[@"token"] = curUser.token;
    param[@"type"] = @(self.listType);
    param[@"page"] = @(self.tableView.refreshPage);
    [CYNET POST:url parameters:param responseCache:^(id responseObject) {
    } success:^(id responseObject) {
        NSMutableArray *modelArray = [UserApiGetUserLikeLogModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
        refreshData(modelArray);
    } failure:^(NSString *error) {
    } hasCache:NO];
}
#pragma mark - Method
#pragma mark - ConstructionScript
- (void)configSelf {
    [self setHiddenForTabBar:YES navigationBar:NO];
}
- (void)allocateComponents {
    self.tableView = (UITableView *)[[UITableView alloc] init]
    .fp_separatorStyle(UITableViewCellSeparatorStyleNone)
    .fp_delegate(self)
    .fp_dataSource(self)
    .fp_enableRefreshAndSetRefreshDelegate(self)
    .fp_refreshPageCount(15);
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([OmDestinyListVCTableViewCell class]) bundle:nil] forCellReuseIdentifier:CellReuseID];
    [self.view addSubview:self.tableView];
}
- (void)layoutComponents {
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
}
@end
